package com.jstyle.jclifexd.utils;

import com.jstyle.jclifexd.NetWork.NetWorkUtil;
import com.jstyle.jclifexd.daoManager.UserInfoDaoManager;
import com.jstyle.jclifexd.model.UserInfo;

import java.util.Calendar;

/**
 * Created by Administrator on 2019/4/18.
 */

public class HealthDataUtils {
    public static int getHrvLevel(int hrvValue){
        int level=3;
        if (hrvValue > 0 && hrvValue < 30) {
            level=3;
        } else if (hrvValue >= 30 && hrvValue < 60) {
            level=2;
        } else if (hrvValue >= 60 && hrvValue < 100) {
            level=1;
        } else if (hrvValue >= 100) {
            level=0;
        }
        return level;
    }
    public static int getStressLevel(int stressValue){
        int level=0;
        if (stressValue > 0 && stressValue <=40) {
            level=0;
        } else if (stressValue >40 && stressValue <= 60) {
            level=1;
        } else if (stressValue >60 && stressValue <= 80) {
            level=2;
        } else if (stressValue >80) {
            level=3;
        }
        return level;
    }
    public static int getHeartRange(float heartRateV, int MHR) {
        int range = 0;
        float heartRate = heartRateV;
        if (heartRate >= 0.5f * MHR && heartRate <= 0.6f * MHR) {//热身
            range = 0;
        } else if (heartRate >= 0.6f * MHR && heartRate < 0.7f * MHR) {//燃脂
            range = 1;
        } else if (heartRate >= 0.7f * MHR && heartRate < 0.8f * MHR) {//有氧
            range = 2;
        } else if (heartRate >= 0.8f * MHR && heartRate < 0.9f * MHR) {//肌力
            range = 3;
        } else if (heartRate >= 0.9f * MHR) {//无氧
            range = 4;
        }
        return range;
    }

    public static int getMaxHr() {
        String account = NetWorkUtil.getUserId();
        UserInfo userInfo = UserInfoDaoManager.getUserByUid(account);
        if (userInfo == null) {
            userInfo = new UserInfo();
            userInfo.setUserId(account);
            UserInfoDaoManager.insertUser(userInfo);
        }
        String birthday = userInfo.getBirthday();
        int userYear = Integer.parseInt(birthday.split("-")[0]);
        Calendar calendar = Calendar.getInstance();
        int age = calendar.get(Calendar.YEAR) - userYear;
        return 220 - age;
    }
    public static int getHeartRange(float heartRateV) {
        int MHR=getMaxHr();

        return getHeartRange(heartRateV,MHR);
    }

    public static int getTempLevel(float temp){
        int tempLevel=0;
        if(temp<36.4){
            tempLevel=0;
        }else if(temp<37.2){
            tempLevel=1;
        }else {
            tempLevel=2;
        }
        return tempLevel;
    }
}
